package cn.gok.controller;

import cn.gok.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
        @RestController 注解：   当前Controller 的所有方法都响应JSON数据
 */
@RestController
public class UserController2 {

    /**
        在方法上，添加@ResponseBody注解，则Spring MVC会自动将返回的
        结果封装成JSON字符串，响应给前端。
     */
    @RequestMapping("/test03")
    public Map<String,Object> testJson03(String userName,String password){
        System.out.println("userName: " + userName);
        System.out.println("password: " + password);
        Map<String, Object> result = new HashMap<>();
        result.put("code","200");
        result.put("msg","操作成功");
        return result;
    }


    @RequestMapping("/test04")
    public Map<String,Object> testJson04(User user){
        System.out.println(user);
        
        Map<String, Object> result = new HashMap<>();
        result.put("code","200");
        result.put("msg","操作成功");
        return result;
    }
}
